<?php
/**
 *  NevuxBB - Free Forum Software
 *  Copyright (C) 2008, 2010 NevuxBB (No one specific author)*  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Memberlist
 * File: memberlist.php
 * Purpose: Showing all members with(out) organisation
 * Todo: Finished writing and add extra ordering types
 *
 */
				
require('system/files/global.php');

// start the initalisation of the page
$core_template_system->setvar('page_title', 'Members List');

// show the header loaded
$core_template_system->pparse();

// include the right language file
$core_lang_system->add_file('member_list');
/*
// begin checking what needs to be loaded
if(is_numeric(isset($_GET['x'])) && is_numeric(isset($_GET['y']))) {
	// there are some custom ordering settings set which are numeric
	if(is_numeric(isset($_GET['p']))) {
		// goto this page
		$page_num = Db_Abstraction::clean($_GET['p']);
	} else {
		// start at 0
		$page_num = 0;
	}
	
	// we need to generate pagination at some point
}*/

// pre-set rules
$total_members = 0;

// actual query
$user_info = Db_Abstraction::query("SELECT *,
										   UNIX_TIMESTAMP(user_regdate) AS `unix_time`, 
										   COUNT(`nbb_users`.`user_id` = `nbb_posts`.`post_user_id`) AS `posts`
									FROM `nbb_users`LEFT JOIN `nbb_posts` 
									ON `nbb_users`.`user_id` = `nbb_posts`.`post_user_id` 
									GROUP BY `nbb_users`.`user_id`");

// loop through users
while($row = DB_Abstraction::fetch_assoc($user_info)) {
	// are we allowing public email?
	if($row['user_showemail'] == 'yes' ) {
		$email = $row['user_email'];
	} else {
		$email = NULL;
	}
	
	// assign variables to loop
	$loop[] = array('u_id' => $row['user_id'], 
					'u_name' => $row['user_name'], 
					'u_defaultgroup' => 'No Default Group',
					'u_posts' => $row['posts'],
					'u_msn' => $row['user_msn'],
					'u_aim' => $row['user_aim'],
					'u_yahoo' => $row['user_yahoo'],
					'u_skype' => $row['user_skype'],
					'u_email' => $email,
					'u_regdate' => date('d/m/Y',$row['unix_time'])
	);

	// increment list
	$total_members++;
}

// start the memberlist loop
$core_template_system->setloop('loop', $loop);

// define some default language variables and urls
$core_template_system->setvar(array(
	'username'            => $core_lang_system->get_var('USERNAME', 4),
	'password'            => $core_lang_system->get_var('PASSWORD', 4),
	'rem_me'              => $core_lang_system->get_var('REMEMBER_ME', 4),
	'nav'                 => $core_lang_system->get_var('NAVIGATION', 4),
	'board_i'             => $core_lang_system->get_var('B_INDEX', 4),
	'members'             => $core_lang_system->get_var('MEMBERS', 4),
	'search' 		      => $core_lang_system->get_var('SEARCH', 4),
	'rules'			      => $core_lang_system->get_var('RULES', 4),
	'ucontrols'		      => $core_lang_system->get_var('USER_CONTROLS', 4),
	'service_information' => $core_lang_system->get_var('SERVICE_I', 4),
	'index_location'      => urlSystem::navParts(1),
	'memberlist_location' => urlSystem::viewURL(4, ' '),
	'search_location'     => urlSystem::navParts(2),
	'rules_location'      => urlSystem::navParts(3),
	'breadcrumb'          => $core_nav_system->generateNav(array('settings' => array('level_down' => false,
																					'main_class' => 'menu'),
																					'information' => array(
																						'home' => array('data' => array(1 => 'Home', 2 => 1)),
																						'members' => array('data' => array(1 => 'Members List', 2 => 5))
																					)))));




// define page specific language and url variables
$core_template_system->setvar(array(
	'ml_name'         		=> $core_lang_system->get_var('ml_name', 3),
	'ml_username_group'     => $core_lang_system->get_var('ml_username_group', 3),
	'ml_posts'            	=> $core_lang_system->get_var('ml_posts', 3),
	'ml_msn'            	=> $core_lang_system->get_var('ml_msn', 3),
	'ml_aim'            	=> $core_lang_system->get_var('ml_aim', 3),
	'ml_yahoo'            	=> $core_lang_system->get_var('ml_yahoo', 3),
	'ml_skype'            	=> $core_lang_system->get_var('ml_skype', 3),
	'ml_email'            	=> $core_lang_system->get_var('ml_email', 3),
	'ml_date_registered'  	=> $core_lang_system->get_var('ml_date_registered', 3),
	'no_members_available'	=> $core_lang_system->get_var('no_members_available', 3),
	'total_members' 	 	=> $total_members
	));

// render the page
$core_template_system->newTemplate(BASE_PATH . '/templates/' . ForumSettings::getCurrentTemplate() . '/member_list.html');
$core_template_system->pparse();

// unset variables
$core_template_system->clearLoops();

// include footer
require(BASE_PATH . '/system/files/footer.php');
?>